﻿Public Class Popup

    Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
        Me.Close()
    End Sub
    Public parent As Form3
    Public errorThis As Boolean = False
    Public Sub CloseMe()
        Me.Close()
    End Sub
    Dim WImage As Integer
    Private Sub Popup_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            PictureBox2.Image = Nothing
            Dim DelayRand As New Random
            Dim Delay As Integer = DelayRand.Next(0, 3000)
            Timer2.Interval = Delay
            Timer2.Enabled = True
        Catch ex As Exception
            ErrorOccurred()
        End Try
    End Sub
    Dim Tick As Integer = 0
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Try
            Tick += 1
            If WImage = 2 And Tick = 11 Then
                Reposition()
            ElseIf WImage = 2 And Tick = 17 Then
                RemoveMeOnList()
            ElseIf WImage = 1 And Tick = 4 Then
                Reposition()
            ElseIf WImage = 1 And Tick = 10 Then
                RemoveMeOnList()
            ElseIf WImage = 3 And Tick = 12 Then
                Reposition()
            ElseIf WImage = 3 And Tick = 18 Then
                RemoveMeOnList()
            ElseIf WImage = 4 And Tick = 15 Then
                Reposition()
            ElseIf WImage = 4 And Tick = 20 Then
                RemoveMeOnList()
            ElseIf WImage = 5 And Tick = 15 Then
                Reposition()
            ElseIf WImage = 5 And Tick = 20 Then
                RemoveMeOnList()
            ElseIf WImage = 6 And Tick = 7 Then
                Reposition()
            ElseIf WImage = 6 And Tick = 12 Then
                RemoveMeOnList()
            ElseIf WImage = 7 And Tick = 13 Then
                Reposition()
            ElseIf WImage = 7 And Tick = 18 Then
                RemoveMeOnList()
            End If
        Catch ex As Exception
            ErrorOccurred()
        End Try
    End Sub
    Sub RemoveMeOnList()
        Try
            parent.ListofPopup.Remove(Me)
            Console.WriteLine(parent.ListofPopup.Count)
            Me.Close()
        Catch ex As Exception
            ErrorOccurred()
        End Try
    End Sub
    Sub ErrorOccurred()
        Try
            parent.UnloadPopUps()
        Catch ex As Exception

        End Try
    End Sub

    Dim XofScreen As Integer = Screen.PrimaryScreen.Bounds.Width
    Dim YofScreen As Integer = Screen.PrimaryScreen.Bounds.Height
    Sub Reposition()
        parent.ShowFireWorks(1)
    End Sub
    Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
        Try
            Dim RandImage As New Random
            WImage = RandImage.Next(2, 4)
            PictureBox2.Image = My.Resources.ResourceManager.GetObject(WImage)
            Dim RandH As New Random
            Dim PopSize As Integer = RandH.Next(150, 580)
            Me.Height = PopSize
            Me.Width = PopSize
            Timer1.Enabled = True
            Timer2.Enabled = False
        Catch ex As Exception
            ErrorOccurred()
        End Try

    End Sub

End Class